package com.sinoma.G2project.MoYu.app;


import com.alibaba.fastjson.JSON;
import com.firenay.common.constant.AuthServerConstant;
import com.firenay.common.utils.R;
import com.firenay.common.vo.MemberRsepVo;
import com.sinoma.G2project.MoYu.Service.DataSelectService;
import com.sinoma.G2project.MoYu.vo.MoYuVo;
import com.sinoma.G2project.utils.jsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/MoYu")
public class updateController {

    @Autowired
    private DataSelectService dataSelectService;


    @GetMapping("/update")
    public R getData(HttpSession session) {
        if (session.getAttribute(AuthServerConstant.LOGIN_USER) == null) {
            return null;
        }

        MemberRsepVo res = (MemberRsepVo) session.getAttribute(AuthServerConstant.LOGIN_USER);
        MoYuVo vo = dataSelectService.getLatest();
        dataSelectService.checkUser(vo,res);
        jsonUtils utils = new jsonUtils();
        String s = utils.getjson();
        Map parse =(Map) JSON.parse(s);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("vo", vo);
        map.put("dict",parse);
        if (res.getUsername() == "admin"){
            return R.ok().put("item", map);
        }else{
            return R.ok().put("item", map);
        }
    }

}
